import { list, getInfo, edit } from "../../api/index.js";
Page({
  data: {
    selectedIndex: -1, // 默认没有选中任何项
    arr: [
      // { id: 0, price1: 5, price2: 30, title: "生鲜果蔬红包", time: "2017/08/02", phone:"限生鲜果蔬频道使用。仅限*********用户使用。"},
      // { id: 1, price1: 10, price2: 40, title: "生鲜果蔬红包", time: "2023/08/02", phone: "限生鲜果蔬频道使用。仅限********用户使用。" },
      // { id: 2, price1: 15, price2: 60, title: "生鲜果蔬红包", time: "2023/08/02", phone: "限生鲜果蔬频道使用。仅限********用户使用。" },
      // { id: 3, price1: 8, price2: 30, title: "生鲜果蔬红包", time: "2023/08/02", phone: "限生鲜果蔬频道使用。仅限********用户使用。" },
      // { id: 4, price1: 6, price2: 20, title: "生鲜果蔬红包", time: "2023/08/02", phone: "限生鲜果蔬频道使用。仅限********用户使用。" },
    ],
    price: 999,
  },
  onLoad(options) {
    var that = this;
    if (options.price) {
      this.setData({
        price: options.price,
      });
    }

    this.getList();
  },
  async getList() {
    var that = this;
    const params = {
      pageNum: 1,
      pageSize: 100,
      userId: wx.getStorageSync("userInfo").userId,
    };
    const table = "envelope";
    const res = await list(params, table);
    if (res.code == 200) {
      this.setData({
        arr: res.rows,
      });
    }
  },
  selectPackage: function (e) {
    const id = e.currentTarget.dataset.id;
    const index = e.currentTarget.dataset.index;
    if (this.data.price < this.data.arr[index].conditionPrice) {
      return;
    }
    this.setData({
      selectedIndex: id,
    });
    const app = getApp();
    app.globalData.backData = { envelope: id };
    // console.log('选中了第', index, '个红包');
  },
});
